const router = require("koa-router")()
const fs = require("fs")
const path = require("path")
const { getFileStream } = require("../../controller/upload/LOCATION.SAVE.CONTROLLER")
const { randomUUID } = require("crypto")
router.prefix("/upfile")



// 上传文件
router.post("/upload", async (ctx, next) => {
    try {
        console.log("上传监听：\n", ctx)
        const { userId, userName, files, } = ctx.request;
        const res = await getFileStream({
            files,
            id: `${randomUUID()}`
        })

        if (res) {
            ctx.body = {
                status: "0000",
                message: "图片上传成功",
                data: res
            }
        } else {
            ctx.body = {
                status: "0010",
                message: "图片上传失败"
            }
        }


        // }


    } catch (error) {
        console.log("错误点：", error)
        ctx.body = {
            status: "1000",
            message: "服务器故障",
        }
    }
})




module.exports = router